package com.itbaizhan.zookeeper.rmi.client;

import com.itbaizhan.zookeeper.rmi.common.HelloService;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.Remote;
import java.rmi.RemoteException;

public class RmiClient {
    public static void main(String[] args) throws MalformedURLException, NotBoundException, RemoteException {
        System.out.println("rmi client running...");
        String url = "rmi://localhost:1099/com.itbaizhan.zookeeper.rmi.server.HelloServiceImpl";
//        寻找发布对象，并且返回对象且强制转换
        Remote lookup =  Naming.lookup(url);
        HelloService helloService = (HelloService)lookup;
//        调用方法
        String result = helloService.sayHello("gtjin");
        System.out.println("client result:"+result);
    }
}
